#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<=b;i++)
int n,m;
const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};
char mapInfo[105][105];
int vis[105][105];
void dfs(int x,int y,char now){
    if(x < 1 || x > n || y < 1 || y > m) return;
    
    if(mapInfo[x][y] == now && vis[x][y] == 0){
        vis[x][y] = 1;
        rep(i,0,3){
            int nx = x + dx[i];
            int ny = y + dy[i];
            dfs(nx,ny,now);
        }
    }
}
void solve(int cycle){
    while(cin >> n >> m){
        if(n == 0 && m == 0) exit(0);
        memset(vis,0,sizeof(vis));
        rep(i,1,n){
            rep(j,1,m) cin >> mapInfo[i][j];
        }
        int cnt = 0;
        rep(i,1,n){
            rep(j,1,m){
                if(vis[i][j] == 0){
                    dfs(i,j,mapInfo[i][j]);
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
}
int main(){
    solve(1);
}
